package log_config

import (
	"github.com/sirupsen/logrus"
	"os"
)
/*默认log等级是info
LOG_LEVEL设置log等级,panic,fatal,error,warn,info,debug,trace
*/
func init()  {
	customFormatter := new(logrus.TextFormatter)
	//设置是否需要毫秒输出
	logTime := os.Getenv("LOG_TIME")//log等级
	if logTime=="ms"{
		customFormatter.TimestampFormat = "2006-01-02 15:04:05.000"
	}else{
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"
	}

	customFormatter.FullTimestamp = true
	logrus.SetFormatter(customFormatter)

	//设置log等级
	log, err := logrus.ParseLevel(os.Getenv("LOG_LEVEL"))
	if err !=nil{
		log = logrus.InfoLevel
	}
	logrus.SetLevel(log)
   //设置是否追踪
	if os.Getenv("LOG_CALLER") == "true"{
		logrus.SetReportCaller(true)
	}
}